package com.campus.food.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

/**
 * Web MVC配置
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${file.upload.path:/uploads}")
    private String uploadPath;
    
    @Value("${file.access.path:/uploads}")
    private String accessPath;

    /**
     * 配置静态资源访问
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 配置上传文件的访问路径
        registry.addResourceHandler(accessPath + "/**")
                .addResourceLocations("file:" + uploadPath + File.separator);
        
        // 配置其他静态资源（如果需要）
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");
    }
} 